package com.wocao.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获得IOC容器的工具类
 */
@Component
@Slf4j
public class ApplicationContextUtils implements ApplicationContextAware {

    //IOC容器
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //一旦IOC容器创建好，该方法会自动调用，设置ApplicationContext对象
        ApplicationContextUtils.applicationContext = applicationContext;
        log.info("获得了IOC容器:" + applicationContext);
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
